import json

from api.base_service import BaseService


# 预约设置服务
class OrderSettingServiceApi(BaseService):
    # 创建服务名实例属性
    def __init__(self):
        super().__init__()
        self.service = "OrderSettingService"

    # 添加预约设置
    def add(self, list_dict):
        resp = self.client.invoke(self.service, "add", list_dict)
        if resp == 'null':
            return True
        else:
            return False

    # 按月统计预约设置信息
    def get_order_setting_by_month(self, string_years):
        resp = self.client.invoke(self.service, "getOrderSettingByMonth", string_years)
        if resp == 'Failed' or resp == '[]':
            return None
        else:
            return json.loads(resp)

    # 根据日期修改预约设置数量
    def edit_number_by_date(self, dict_data):
        dict_data['class'] = "com.itheima.pojo.OrderSetting"
        resp = self.client.invoke(self.service, "editNumberByDate", dict_data)
        if resp == 'null':
            return True
        else:
            return False


if __name__ == '__main__':
    oss = OrderSettingServiceApi()
    # resp = oss.add([{"orderDate": "2022-12-24 01:11:11", "number": 99764732}])
    # print('响应结果', type(resp), resp)
    # Failed
    # resp = oss.get_order_setting_by_month('2021-9')
    data = {"orderDate": "2022-12-24 01:09:08", "number": '1001'}
    resp = oss.edit_number_by_date({"orderDate": "2022-12-24 01:09:08", "number": '1001'})
    print('响应结果', type(resp), resp)
